package com.wzh.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wzh.product.entity.DiscountEntity;
import com.wzh.product.service.DiscountService;
import com.wzh.common.utils.PageUtils;
import com.wzh.common.utils.R;



/**
 * 
 *
 * @author wzh
 * @email 1281204121@qq.com
 * @date 2022-01-22 21:07:56
 */
@RestController
@RequestMapping("product/discount")
public class DiscountController {
    @Autowired
    private DiscountService discountService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = discountService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{did}")
    public R info(@PathVariable("did") Integer did){
		DiscountEntity discount = discountService.getById(did);

        return R.ok().put("discount", discount);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DiscountEntity discount){
		discountService.save(discount);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DiscountEntity discount){
		discountService.updateById(discount);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] dids){
		discountService.removeByIds(Arrays.asList(dids));

        return R.ok();
    }

}
